// $Id: succeeded_failed.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/result.hpp>
#include <xpcom/result_code.hpp>

BOOST_AUTO_TEST_CASE(test_succeeded_failed)
{
    using namespace xpcom;

    result r0 = NS_OK;
    result r1 = NS_ERROR_NULL_POINTER;
    result r2 = NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;

    BOOST_CHECK(r0.succeeded());
    BOOST_CHECK(!r0.failed());
    BOOST_CHECK(r0.is_ok());

    BOOST_CHECK(!r1.succeeded());
    BOOST_CHECK(r1.failed());
    BOOST_CHECK(!r1.is_ok());

    BOOST_CHECK(r2.succeeded());
    BOOST_CHECK(!r2.failed());
    BOOST_CHECK(!r2.is_ok());

    BOOST_CHECK(result(0).succeeded());
    BOOST_CHECK(result(10000).succeeded());
    BOOST_CHECK(result(0x78000009L).succeeded());
    BOOST_CHECK(result(0x800401f8L).failed());
    BOOST_CHECK(result(0x80040110L).failed());

    BOOST_CHECK(result(0).is_ok());
    BOOST_CHECK(!result(1).is_ok());
}
